
var applyExamineDialog = {
	oThis: null,
	dialog: null,

	detail: null, // 当前选择详情
	approval: null, // 审核状态
	nodeCode: null, // 审批流程编码

	init: function () {
		this.initState();
		this.initEvent();
	},

	initState: function () {
		var _this = this;

		this.oThis = $('#examineDialog');
		this.dialog = new TheDialog('#examineDialog');

	},

	initEvent: function () {
		var _this = this;

		// 提交按钮点击
		this.oThis.find('.submit-btn').on('click', function () {
			_this.submit();
		})

	},

	// 显示
	show: function (detail) {
		this.dialog.show();

		this.getDetail(detail.id);
	},

	// 获取详情
	getDetail: function (id) {
		var _this = this;
		$.ajax({
			type: 'get',
			url: pb.api + '/baImageApply/get',
			data: {
				id: id
			},
			success: function (res) {
				_this.detail = res.data.baImageApply;
				_this.approval = res.data.baApprovalOpinionVOList;

				_this.setDefaultHtml(); // 设置默认显示
			}
		})
	},

	// 提交审核结果
	submit: function () {
		var _this = this;
		var code = this.oThis.find('input[name=exstate]:checked').val();
		var codeName = code == 1 ? '同意' : '不同意';
		if (pb.isEmpty(code)) {
			Qmsg.error('请选择审核状态');
			return;
		}
		var desc = this.oThis.find('.approval-info textarea').val();
		if (code == 0 && !desc) {
			Qmsg.error('请输入审核意见');
			return;
		}
		var param = {
			applyId: this.detail.id, // 流程id
			approvalOpinionCode: code,
			approvalOpinionName: codeName,
			approvalOpinionDesc: desc,
			nodeCode: this.nodeCode
		}
		$.ajax({
			type: 'post',
			url: pb.api + '/baImageApply/audit',
			data: param,
			success: function (res) {
				if (res.result == 'true') {
					Qmsg.success(res.message);
					_this.dialog.close();
					oPage.getData();
				} else {
					Qmsg.error(res.message);
				}
			}
		})
	},

	// 设置默认显示
	setDefaultHtml: function () {
		if (!this.detail) {
			return;
		}
		this.oThis.find('.sqdh-text').html(this.detail.applyNo);
		this.oThis.find('.sqks-text').html(this.detail.deptName);
		this.oThis.find('.sqys-text').html(this.detail.doctorName);
		this.oThis.find('.sqsj-text').html(this.detail.applyTime);

		this.oThis.find('.yxxx-text').html(this.detail.imageName);
		this.oThis.find('.hzxm-text').html(this.detail.patientName);
		this.oThis.find('.hzxb-text').html(this.detail.sex);
		this.oThis.find('.hznl-text').html(this.detail.age);
		this.oThis.find('.hzmz-text').html(this.detail.outpatientCode);
		this.oThis.find('.hzzy-text').html(this.detail.hospitalizedCode);
		this.oThis.find('.hzjc-text').html(this.detail.equipmentDetail);
		this.oThis.find('.hzyx-text').html(this.detail.imageCode);
		this.oThis.find('.dzbw-text').html(this.detail.partName);
		this.oThis.find('.jbzd-text').html(this.detail.diagnosisMark);
		this.oThis.find('.dzly-text').html(this.detail.reasonMark);
		this.oThis.find('.yxsjlx-text').html(pb.getNameByCode(this.detail.imageTypeCode, pb.yxsjlxList));

		this.setApprovalHtml(); // 设置审核信息
	},

	// 设置审核信息
	setApprovalHtml: function () {
		if (!this.approval) {
			return;
		}
		var html = '';
		for (var i = 0; i < this.approval.length; i++) {
			var item = this.approval[i];
			if (pb.isEmpty(item.approvalOpinionCode)) {
				html += '<div class="item is-handing">' +
							'<div class="icon iconfont iconxia"></div>' +
							'<div class="title">' +
								'<span class="t1">' + item.nodeName + '</span>' +
							'</div>' +
							'<div class="state clearfix">' +
								'<span class="label pull-left">审核状态：</span>' +
								'<div class="value pull-left">' +
									'<label class="pull-left">' +
										'<input class="pull-left" type="radio" value="1" name="exstate">' +
										'<span class="pull-left">同意</span>' +
									'</label>' +
									'<label class="pull-left">' +
										'<input class="pull-left" type="radio" value="0" name="exstate">' +
										'<span class="pull-left">不同意</span>' +
									'</label>' +
								'</div>' +
							'</div>' +
							'<div class="idea clearfix">' +
								'<span class="label pull-left">审批意见：</span>' +
								'<div class="value pull-left">' +
									'<textarea class="com-textarea" rows="3"></textarea>' +
								'</div>' +
							'</div>' +
						'</div>';
				this.nodeCode = item.nodeCode;
				break;
			} else if (item.approvalOpinionCode === 0) {
				break;
			} else {
				html += '<div class="item">' +
							'<div class="icon iconfont icongou"></div>' +
							'<div class="title">' +
								'<span class="t1">' + item.nodeName + '</span>' +
								'<span class="result ' + (item.approvalOpinionCode == 1 ? 'success' : 'error') + '">' + item.approvalOpinionName + '</span>' +
							'</div>' +
							'<div class="sign">' +
								'<span class="name">' + item.approvalUserName + '</span>' +
								'<span>' + item.approvalTime + '</span>' +
							'</div>' +
							'<div class="idea">' +
								'<span class="label">审批意见：</span>' +
								'<span class="value">' + item.approvalOpinionDesc + '</span>' +
							'</div>' +
						'</div>';
			}
		}
		this.oThis.find('.approval-info .list').html(html);
	}

}

$(function () {
	applyExamineDialog.init();
})


